package org.emet.dao;

import org.emet.jee.console.entity.sys.Archive;
import org.emet.jee.core.dao.Page;
import org.emet.jee.core.dao.arch.ArchDataSourceBaseDao;
import org.emet.service.dto.ArchiveCriteria;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class ArchiveDao extends ArchDataSourceBaseDao<Archive, Long> {
	public Page<Archive> search(Page<Archive> page, ArchiveCriteria criteria) {
		Criteria c = getSession().createCriteria(Archive.class);
		NonEmptyValueHashMap<String, Object> propertyNameValues = new NonEmptyValueHashMap<String, Object>();
		propertyNameValues.put("name", criteria.getName());
		propertyNameValues.put("jdbcServer", criteria.getJdbcServer());
		propertyNameValues.put("jdbcPort", criteria.getJdbcPort());
		propertyNameValues.put("jdbcSchema", criteria.getJdbcSchema());
		propertyNameValues.put("jdbcUsername", criteria.getJdbcUsername());
		propertyNameValues.put("jdbcPassword", criteria.getJdbcPassword());
		propertyNameValues.put("remark", criteria.getRemark());
		c.add(Restrictions.allEq(propertyNameValues));
		page.setOrderBy("id");
		page.setOrder("desc");
		return findPage(page, c);
	}
}
